package com.woniuxy.web.back;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.entity.Order;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.User;
import com.woniuxy.service.OrderService;
import com.woniuxy.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin(value="http://192.168.6.186:8080",allowCredentials = "true")
//统一前缀为user
@RequestMapping("admin/order")
public class OrderController_b {
    @Autowired
    private OrderService orderService;

   /**
   * @description:订单展示
    * @return: com.woniuxy.entity.ResponseEntity<java.util.List<com.woniuxy.entity.User>>
    * @date: 2021/8/12 15:32
    * @author: 魏炳豪
    */
    @GetMapping("list")
    public ResponseEntity<List<Order>> list(){
        //获取全部用户信息
        List<Order> orders = orderService.getAllOrders();
        return new ResponseEntity<List<Order>>(orders);
    }

//    @GetMapping("search/{query}")
//    public ResponseEntity<List<Order>> search(@PathVariable String query){
//        Order order = new Order();
//        order.setOrderNum(query);
//        List<Order> orders = orderService.getByCondition(order);
//        return new ResponseEntity<List<Order>>(orders);
//    }
    @GetMapping("status/{id}")
    public ResponseEntity<List<Order>> status(@PathVariable String id){
        Order order = new Order();
        order.setStatus(id);
        List<Order> orders = orderService.getByCondition(order);
        return new ResponseEntity<List<Order>>(orders);
    }
    @GetMapping("pageList")

    public ResponseEntity<List<Order>> pageList(Integer current,String query,Integer pageSize,Order order,String startTime ,String endTime){
        if(current == null || current == 0){
            current=1;
        }
        if(pageSize == null || pageSize == 0){
            pageSize=2;
        }

        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        if (query != null && query.trim().length() != 0) {
            queryWrapper.like("order_number", query);
        }
        if (order.getStatus() != null && order.getStatus().trim().length() != 0) {
            queryWrapper.like("status", order.getStatus());
        }
        if(startTime !=null && startTime.trim().length() != 0){
            queryWrapper.ge("order_time",startTime);
        }
        if(endTime != null && endTime.trim().length() !=0){
            queryWrapper.le("order_time",endTime);
        }
        Page<Order> page = new Page<>(current, pageSize);
        page = orderService.page(page, queryWrapper);
        return new ResponseEntity(page);

    }




}
